<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Usage Scenarios - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.ldap.usage.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.ldap.usage.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.ldap.api.html">API overview</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.ldap.html">Zend_Ldap</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.ldap.tools.html">Tools</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.ldap.usage" class="section"><div class="info"><h1 class="title">Usage Scenarios</h1></div>
    

    <div class="section" id="zend.ldap.usage.authentication"><div class="info"><h1 class="title">Authentication scenarios</h1></div>
        

        <div class="section" id="zend.ldap.usage.authentication.openldap"><div class="info"><h1 class="title">OpenLDAP</h1></div>
            
            <p class="para"/>
        </div>

        <div class="section" id="zend.ldap.usage.authentication.activedirectory"><div class="info"><h1 class="title">ActiveDirectory</h1></div>
            
            <p class="para"/>
        </div>
    </div>

    <div class="section" id="zend.ldap.usage.basic"><div class="info"><h1 class="title">Basic CRUD operations</h1></div>
        

        <div class="section" id="zend.ldap.usage.basic.retrieve"><div class="info"><h1 class="title">Retrieving data from the LDAP</h1></div>
            

            <div class="example" id="zend.ldap.usage.basic.retrieve.dn"><div class="info"><p><b>Example #1 Getting an entry by its DN</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$hm = $ldap-&gt;getEntry(&#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;);
/*
$hm is an array of the following structure
array(
    &#039;dn&#039;          =&gt; &#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;,
    &#039;cn&#039;          =&gt; array(&#039;Hugo Müller&#039;),
    &#039;sn&#039;          =&gt; array(&#039;Müller&#039;),
    &#039;objectclass&#039; =&gt; array(&#039;inetOrgPerson&#039;, &#039;top&#039;),
    ...
)
*/
</pre>

            </div>

            <div class="example" id="zend.ldap.usage.basic.retrieve.exists"><div class="info"><p><b>Example #2 Check for the existence of a given DN</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$isThere = $ldap-&gt;exists(&#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;);
</pre>

            </div>

            <div class="example" id="zend.ldap.usage.basic.retrieve.counting-children"><div class="info"><p><b>Example #3 Count children of a given DN</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$childrenCount = $ldap-&gt;countChildren(
                            &#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;);
</pre>

            </div>

            <div class="example" id="zend.ldap.usage.basic.retrieve.search"><div class="info"><p><b>Example #4 Searching the LDAP tree</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$result = $ldap-&gt;search(&#039;(objectclass=*)&#039;,
                        &#039;ou=People,dc=my,dc=local&#039;,
                        Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
foreach ($result as $item) {
    echo $item[&quot;dn&quot;] . &#039;: &#039; . $item[&#039;cn&#039;][0] . PHP_EOL;
}
</pre>

            </div>
        </div>

        <div class="section" id="zend.ldap.usage.basic.add"><div class="info"><h1 class="title">Adding data to the LDAP</h1></div>
            

            <div class="example" id="example-505"><div class="info"><p><b>Example #5 Add a new entry to the LDAP</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$entry = array();
Zend_Ldap_Attribute::setAttribute($entry, &#039;cn&#039;, &#039;Hans Meier&#039;);
Zend_Ldap_Attribute::setAttribute($entry, &#039;sn&#039;, &#039;Meier&#039;);
Zend_Ldap_Attribute::setAttribute($entry, &#039;objectClass&#039;, &#039;inetOrgPerson&#039;);
$ldap-&gt;add(&#039;cn=Hans Meier,ou=People,dc=my,dc=local&#039;, $entry);
</pre>

            </div>
        </div>

        <div class="section" id="zend.ldap.usage.basic.delete"><div class="info"><h1 class="title">Deleting from the LDAP</h1></div>
            

            <div class="example" id="example-506"><div class="info"><p><b>Example #6 Delete an existing entry from the LDAP</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$ldap-&gt;delete(&#039;cn=Hans Meier,ou=People,dc=my,dc=local&#039;);
</pre>

            </div>
        </div>

        <div class="section" id="zend.ldap.usage.basic.update"><div class="info"><h1 class="title">Updating the LDAP</h1></div>
            

            <div class="example" id="example-507"><div class="info"><p><b>Example #7 Update an existing entry on the LDAP</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$hm = $ldap-&gt;getEntry(&#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;);
Zend_Ldap_Attribute::setAttribute($hm, &#039;mail&#039;, &#039;mueller@my.local&#039;);
Zend_Ldap_Attribute::setPassword($hm,
                                 &#039;newPa$$w0rd&#039;,
                                 Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
$ldap-&gt;update(&#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;, $hm);
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.ldap.usage.extended"><div class="info"><h1 class="title">Extended operations</h1></div>
        

        <div class="section" id="zend.ldap.usage.extended.copy-and-move"><div class="info"><h1 class="title">Copy and move entries in the LDAP</h1></div>
            

            <div class="example" id="zend.ldap.usage.extended.copy-and-move.copy"><div class="info"><p><b>Example #8 Copy a LDAP entry recursively with all its descendants</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$ldap-&gt;copy(&#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;,
            &#039;cn=Hans Meier,ou=People,dc=my,dc=local&#039;,
            true);
</pre>

            </div>

            <div class="example" id="zend.ldap.usage.extended.copy-and-move.move-to-subtree"><div class="info"><p><b>Example #9 
                    Move a LDAP entry recursively with all its descendants to a different subtree
                </b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(/* ... */);
$ldap = new Zend_Ldap($options);
$ldap-&gt;bind();
$ldap-&gt;moveToSubtree(&#039;cn=Hugo Müller,ou=People,dc=my,dc=local&#039;,
                     &#039;ou=Dismissed,dc=my,dc=local&#039;,
                     true);
</pre>

            </div>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.ldap.api.html">API overview</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.ldap.html">Zend_Ldap</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.ldap.tools.html">Tools</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.ldap.html">Zend_Ldap</a></li>
  <li><a href="zend.ldap.introduction.html">Introduction</a></li>
  <li><a href="zend.ldap.api.html">API overview</a></li>
  <li class="active"><a href="zend.ldap.usage.html">Usage Scenarios</a></li>
  <li><a href="zend.ldap.tools.html">Tools</a></li>
  <li><a href="zend.ldap.node.html">Object oriented access to the LDAP tree using Zend_Ldap_Node</a></li>
  <li><a href="zend.ldap.server.html">Getting information from the LDAP server</a></li>
  <li><a href="zend.ldap.ldif.html">Serializing LDAP data to and from LDIF</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>